package com.ruoyi.fly.service.impl;

import java.util.List;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.fly.domain.AmountView;
import com.ruoyi.fly.domain.Referralrewards;
import com.ruoyi.fly.domain.ShareAmountView;
import com.ruoyi.fly.domain.vo.AmountViewVo;
import com.ruoyi.fly.domain.vo.ReferralrewardsVo;
import com.ruoyi.fly.mapper.ReferralrewardsMapper;
import com.ruoyi.fly.service.ReferralrewardsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 分享消费奖励Service业务层处理
 */
@Service
public class ReferralrewardsServiceImpl implements ReferralrewardsService {
    @Autowired
    private ReferralrewardsMapper referralrewardsMapper;

    /**
     * 查询分享消费奖励
     *
     * @param id 分享消费奖励主键
     * @return 分享消费奖励
     */
    @Override
    public Referralrewards selectReferralrewardsById(String id) {
        return referralrewardsMapper.selectReferralrewardsById(id);
    }

    @Override
    public Referralrewards selectReferralrewards() {
        return referralrewardsMapper.selectReferralrewards();
    }

    /**
     * 查询分享消费奖励统计
     *
     * @param amountViewVo
     * @return
     */
    @Override
    public R selectAmountViewList(AmountViewVo amountViewVo) {
        PageHelper.startPage(amountViewVo.getPageNum(), amountViewVo.getPageSize());
        List<AmountView> amountViews = referralrewardsMapper.selectAmountViewList(amountViewVo);
        PageInfo<AmountView> pageInfo = new PageInfo<>(amountViews);
        return R.ok(pageInfo);
    }

    /**
     * 查询分享奖励统计
     *
     * @param amountViewVo
     * @return
     */
    @Override
    public R selectShareAmountViewList(AmountViewVo amountViewVo) {
        PageHelper.startPage(amountViewVo.getPageNum(), amountViewVo.getPageSize());
        List<ShareAmountView> shareAmountViews = referralrewardsMapper.selectShareAmountViewList(amountViewVo);
        PageInfo<ShareAmountView> pageInfo = new PageInfo<>(shareAmountViews);
        return R.ok(pageInfo);
    }


    /**
     * 修改分享消费奖励
     *
     * @param referralrewards 分享消费奖励
     * @return 结果
     */
    @Override
    public R updateReferralrewards(ReferralrewardsVo referralrewards) {
        referralrewards.setUpdateUser(SecurityUtils.getUserId());
        referralrewards.setId("1");
        return referralrewardsMapper.updateReferralrewards(referralrewards)>0?R.ok("修改成功"):R.fail("操作失败");
    }
}
